package com.supor.aiot.common.interfaces;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import androidx.annotation.NonNull;

/**
 * item的点击事件，避免在1秒内触发多次点击
 *
 */
public abstract class OnItemFilterClickListener implements OnItemClickListener {

    private long mLastClickTime = 0;
    private long mTimeInterval = 1000L;

    public OnItemFilterClickListener() {

    }

    public OnItemFilterClickListener(long interval) {
        this.mTimeInterval = interval;
    }

    @Override
    public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View v,
                            int position) {
        long nowTime = System.currentTimeMillis();
        if (nowTime - mLastClickTime > mTimeInterval) {
            mLastClickTime = nowTime;
            // 单次点击事件
            onSingleClick(adapter, v, position);
        }
    }

    /**
     * 单次点击事件
     */
    protected abstract void onSingleClick(@NonNull BaseQuickAdapter<?, ?> adapter, View v, int position);

}
